<template>
    <div>
        Recent

        <div class="chat-list">

            <div class="chat-list-item" v-for="(item,index) in userList" :key="index">

                <div style="position:relative;">
                    <el-avatar :size="44" :src="avImg"/>
                    <div
                        style="position:absolute;top:33px;left: 35px;background-color: #34c38f;width: 12px;height: 12px;border-radius: 50px"/>
                </div>
                <div class="chat-list-item-info" @click="chatClick(item)">
                    <div class="chat-list-item-name">
                        {{ item.users.userName }}
                    </div>
                    <div class="chat-list-item-message">
                        {{ item.lastMessage.msgContent }}
                    </div>
                    <div class="chat-list-item-time">
                        {{ formatTime(item.lastMessage.msgTime) }}
                    </div>
                    <div v-if="item.unread!==0" class="chat-list-item-unread">
                        {{ item.unread }}
                    </div>
                </div>
            </div>

        </div>
    </div>
</template>

<script>
import moment from "moment";

export default {
    name: "ChatList",
    props: ['userList'],
    data() {
        return {
            avImg: require("@/assets/icon/3.png"),
        }
    },
    methods: {
        chatClick(item) {
            console.log(item.users)
            console.log('tosenddata', item)
            this.$emit("togglePage", "chatroom", "enter")
            this.$emit("setCurrentChatUserId", item.users.userId)
            this.$emit("setChatRoomData", item)



        },
        formatTime(time) {
            return moment(time).format("HH:mm:ss")
        }
    },
    mounted() {


    }
}
</script>

<style scoped>
.chat-list {

    margin-top: 10px;
    height: 450px;
    overflow-y: hidden;
    transition: all ease-in-out 300ms;
}

.chat-list:hover {
    margin-top: 10px;
    height: 450px;
    overflow-y: auto;
}

.chat-list-item {
    display: flex;
    padding-left: 20px;
    padding-right: 20px;
    padding-top: 15px;
    padding-bottom: 15px;
    align-items: center;
    border-top: #e9eaee 1px solid;
    transition: all ease-in-out 300ms;
    cursor: pointer;


}

.chat-list-item:hover {

    background-color: white;
    box-shadow: 0 0.75rem 1.5rem rgba(18, 38, 63, 0.03);
}

.chat-list-item-info {
    position: relative;
    display: flex;
    flex-direction: column;
    margin-left: 20px;
    width: 100%;
}

.chat-list-item-name {
    font-weight: normal;
    font-size: 16px;
    font-family: Poppins, sans-serif;
}

.chat-list-item-message {
    color: #8b8ea0;
    font-size: 14px;
}

.chat-list-item-time {
    position: absolute;
    right: 10px;
}

.chat-list-item-unread {
    position: absolute;
    right: 20px;
    top: 30px;
    background-color: coral;
    color: white;
    border-radius: 50px;
    min-width: 25px;
    text-align: center;
    line-height: 27px;
    height: 25px;
}
</style>